home *** CD-ROM | disk | FTP | other *** search
/ The Arsenal Files 8 / The Arsenal Files Collection #8 (Arsenal Computer) (1996).ISO / g_quake / ultqsrc.zip / BUILTIN.C < prev    next >
C/C++ Source or Header  |  1996-09-10  |  31KB  |  1,599 lines

  1.  
  2. #include "quakedef.h"
  3.  
  4. #define    RETURN_EDICT(e) (((int *)pr_globals)[OFS_RETURN] = EDICT_TO_PROG(e))
  5.  
  6. /*
  7. ===============================================================================
  8.  
  9.                         BUILT-IN FUNCTIONS
  10.  
  11. ===============================================================================
  12. */
  13.  
  14. char *PF_VarString (int    first)
  15. {
  16.     int        i;
  17.     static char out[256];
  18.     
  19.     out[0] = 0;
  20.     for (i=first ; i<pr_argc ; i++)
  21.     {
  22.         strcat (out, G_STRING((OFS_PARM0+i*3)));
  23.     }
  24.     return out;
  25. }
  26.  
  27.  
  28. /*
  29. =================
  30. PF_errror
  31.  
  32. This is a TERMINAL error, which will kill off the entire server.
  33. Dumps self.
  34.  
  35. error(value)
  36. =================
  37. */
  38. void PF_error (void)
  39. {
  40.     char    *s;
  41.     edict_t    *ed;
  42.     
  43.     s = PF_VarString(0);
  44.     Con_Printf ("======SERVER ERROR in %s:\n%s\n"
  45.     ,pr_strings + pr_xfunction->s_name,s);
  46.     ed = PROG_TO_EDICT(pr_global_struct->self);
  47.     ED_Print (ed);
  48.  
  49.     Host_Error ("Program error");
  50. }
  51.  
  52.  
  53. =================
  54. PF_objerror
  55.  
  56. Dumps out self, then an error message.  The program is aborted and self is
  57. removed, but the level can continue.
  58.  
  59. objerror(value)
  60. =================
  61.  
  62. void PF_objerror (void)
  63. {
  64.     char    *s;
  65.     edict_t    *ed;
  66.     
  67.     s = PF_VarString(0);
  68.     Con_Printf ("======OBJECT ERROR in %s:\n%s\n"
  69.     ,pr_strings + pr_xfunction->s_name,s);
  70.     ed = PROG_TO_EDICT(pr_global_struct->self);
  71.     ED_Print (ed);
  72.     ED_Free (ed);
  73.     
  74.     Host_Error ("Program error");
  75. }
  76.  
  77.  
  78. /*
  79. ==============
  80. PF_makevectors
  81.  
  82. Writes new values for v_forward, v_up, and v_right based on angles
  83. makevectors(vector)
  84. ==============
  85. */
  86. void PF_makevectors (void)
  87. {
  88.     AngleVectors (G_VECTOR(OFS_PARM0), pr_global_struct->v_forward, pr_global_struct->v_right, pr_global_struct->v_up);
  89. }
  90.  
  91. /*
  92. =================
  93. PF_setorigin
  94.  
  95. This is the only valid way to move an object without using the physics of the world (setting velocity and waiting).  Directly changing origin will not set internal links correctly, so clipping would be messed up.  This should be called when an object is spawned, and then only if it is teleported.
  96.  
  97. setorigin (entity, origin)
  98. =================
  99. */
  100. void PF_setorigin (void)
  101. {
  102.     edict_t    *e;
  103.     float    *org;
  104.     
  105.     e = G_EDICT(OFS_PARM0);
  106.     org = G_VECTOR(OFS_PARM1);
  107.     VectorCopy (org, e->v.origin);
  108.     SV_LinkEdict (e, false);
  109. }
  110.  
  111.  
  112. void SetMinMaxSize (edict_t *e, float *min, float *max, qboolean rotate)
  113. {
  114.     float    *angles;
  115.     vec3_t    rmin, rmax;
  116.     float    bounds[2][3];
  117.     float    xvector[2], yvector[2];
  118.     float    a;
  119.     vec3_t    base, transformed;
  120.     int        i, j, k, l;
  121.     
  122.     for (i=0 ; i<3 ; i++)
  123.         if (min[i] > max[i])
  124.             PR_RunError ("backwards mins/maxs");
  125.  
  126.     rotate = false;        // FIXME: implement rotation properly again
  127.  
  128.     if (!rotate)
  129.     {
  130.         VectorCopy (min, rmin);
  131.         VectorCopy (max, rmax);
  132.     }
  133.     else
  134.     {
  135.     // find min / max for rotations
  136.         angles = e->v.angles;
  137.         
  138.         a = angles[1]/180 * M_PI;
  139.         
  140.         xvector[0] = cos(a);
  141.         xvector[1] = sin(a);
  142.         yvector[0] = -sin(a);
  143.         yvector[1] = cos(a);
  144.         
  145.         VectorCopy (min, bounds[0]);
  146.         VectorCopy (max, bounds[1]);
  147.         
  148.         rmin[0] = rmin[1] = rmin[2] = 9999;
  149.         rmax[0] = rmax[1] = rmax[2] = -9999;
  150.         
  151.         for (i=0 ; i<= 1 ; i++)
  152.         {
  153.             base[0] = bounds[i][0];
  154.             for (j=0 ; j<= 1 ; j++)
  155.             {
  156.                 base[1] = bounds[j][1];
  157.                 for (k=0 ; k<= 1 ; k++)
  158.                 {
  159.                     base[2] = bounds[k][2];
  160.                     
  161.                 // transform the point
  162.                     transformed[0] = xvector[0]*base[0] + yvector[0]*base[1];
  163.                     transformed[1] = xvector[1]*base[0] + yvector[1]*base[1];
  164.                     transformed[2] = base[2];
  165.                     
  166.                     for (l=0 ; l<3 ; l++)
  167.                     {
  168.                         if (transformed[l] < rmin[l])
  169.                             rmin[l] = transformed[l];
  170.                         if (transformed[l] > rmax[l])
  171.                             rmax[l] = transformed[l];
  172.                     }
  173.                 }
  174.             }
  175.         }
  176.     }
  177.     
  178. // set derived values
  179.     VectorCopy (rmin, e->v.mins);
  180.     VectorCopy (rmax, e->v.maxs);
  181.     VectorSubtract (max, min, e->v.size);
  182.     
  183.     SV_LinkEdict (e, false);
  184. }
  185.  
  186. /*
  187. =================
  188. PF_setsize
  189.  
  190. the size box is rotated by the current angle
  191.  
  192. setsize (entity, minvector, maxvector)
  193. =================
  194. */
  195. void PF_setsize (void)
  196. {
  197.     edict_t    *e;
  198.     float    *min, *max;
  199.     
  200.     e = G_EDICT(OFS_PARM0);
  201.     min = G_VECTOR(OFS_PARM1);
  202.     max = G_VECTOR(OFS_PARM2);
  203.     SetMinMaxSize (e, min, max, false);
  204. }
  205.  
  206. /*
  207. =================
  208. PF_setmodel
  209.  
  210. setmodel(entity, model)
  211. =================
  212. */
  213. void PF_setmodel (void)
  214. {
  215.     edict_t    *e;
  216.     char    *m, **check;
  217.     model_t    *mod;
  218.     int        i;
  219.  
  220.     e = G_EDICT(OFS_PARM0);
  221.     m = G_STRING(OFS_PARM1);
  222.  
  223. // check to see if model was properly precached
  224.     for (i=0, check = sv.model_precache ; *check ; i++, check++)
  225.         if (!strcmp(*check, m))
  226.             break;
  227.             
  228.     if (!*check)
  229.         PR_RunError ("no precache: %s\n", m);
  230.         
  231.  
  232.     e->v.model = m - pr_strings;
  233.     e->v.modelindex = i; //SV_ModelIndex (m);
  234.  
  235.     mod = sv.models[ (int)e->v.modelindex];  // Mod_ForName (m, true);
  236.     
  237.     if (mod)
  238.         SetMinMaxSize (e, mod->mins, mod->maxs, true);
  239.     else
  240.         SetMinMaxSize (e, vec3_origin, vec3_origin, true);
  241. }
  242.  
  243. /*
  244. =================
  245. PF_bprint
  246.  
  247. broadcast print to everyone on server
  248.  
  249. bprint(value)
  250. =================
  251. */
  252. void PF_bprint (void)
  253. {
  254.     char        *s;
  255.  
  256.     s = PF_VarString(0);
  257.     SV_BroadcastPrintf (s);
  258. }
  259.  
  260. /*
  261. =================
  262. PF_sprint
  263.  
  264. single print to a specific client
  265.  
  266. sprint(clientent, value)
  267. =================
  268. */
  269. void PF_sprint (void)
  270. {
  271.     char        *s;
  272.     client_t    *client;
  273.     int            entnum;
  274.     
  275.     entnum = G_EDICTNUM(OFS_PARM0);
  276.     s = PF_VarString(1);
  277.     
  278.     if (entnum < 1 || entnum > svs.maxclients)
  279.     {
  280.         Con_Printf ("tried to sprint to a non-client\n");
  281.         return;
  282.     }
  283.         
  284.     client = &svs.clients[entnum-1];
  285.         
  286.     MSG_WriteChar (&client->message,svc_print);
  287.     MSG_WriteString (&client->message, s );
  288. }
  289.  
  290.  
  291. /*
  292. =================
  293. PF_centerprint
  294.  
  295. single print to a specific client
  296.  
  297. centerprint(clientent, value)
  298. =================
  299. */
  300. void PF_centerprint (void)
  301. {
  302.     char        *s;
  303.     client_t    *client;
  304.     int            entnum;
  305.     
  306.     entnum = G_EDICTNUM(OFS_PARM0);
  307.     s = PF_VarString(1);
  308.     
  309.     if (entnum < 1 || entnum > svs.maxclients)
  310.     {
  311.         Con_Printf ("tried to sprint to a non-client\n");
  312.         return;
  313.     }
  314.         
  315.     client = &svs.clients[entnum-1];
  316.         
  317.     MSG_WriteChar (&client->message,svc_centerprint);
  318.     MSG_WriteString (&client->message, s );
  319. }
  320.  
  321.  
  322. /*
  323. =================
  324. PF_normalize
  325.  
  326. vector normalize(vector)
  327. =================
  328. */
  329. void PF_normalize (void)
  330. {
  331.     float    *value1;
  332.     vec3_t    newvalue;
  333.     float    new;
  334.     
  335.     value1 = G_VECTOR(OFS_PARM0);
  336.  
  337.     new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
  338.     new = sqrt(new);
  339.     
  340.     if (new == 0)
  341.         newvalue[0] = newvalue[1] = newvalue[2] = 0;
  342.     else
  343.     {
  344.         new = 1/new;
  345.         newvalue[0] = value1[0] * new;
  346.         newvalue[1] = value1[1] * new;
  347.         newvalue[2] = value1[2] * new;
  348.     }
  349.     
  350.     VectorCopy (newvalue, G_VECTOR(OFS_RETURN));    
  351. }
  352.  
  353. /*
  354. =================
  355. PF_vlen
  356.  
  357. scalar vlen(vector)
  358. =================
  359. */
  360. void PF_vlen (void)
  361. {
  362.     float    *value1;
  363.     float    new;
  364.     
  365.     value1 = G_VECTOR(OFS_PARM0);
  366.  
  367.     new = value1[0] * value1[0] + value1[1] * value1[1] + value1[2]*value1[2];
  368.     new = sqrt(new);
  369.     
  370.     G_FLOAT(OFS_RETURN) = new;
  371. }
  372.  
  373. /*
  374. =================
  375. PF_vectoyaw
  376.  
  377. float vectoyaw(vector)
  378. =================
  379. */
  380. void PF_vectoyaw (void)
  381. {
  382.     float    *value1;
  383.     float    yaw;
  384.     
  385.     value1 = G_VECTOR(OFS_PARM0);
  386.  
  387.     if (value1[1] == 0 && value1[0] == 0)
  388.         yaw = 0;
  389.     else
  390.     {
  391.         yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
  392.         if (yaw < 0)
  393.             yaw += 360;
  394.     }
  395.  
  396.     G_FLOAT(OFS_RETURN) = yaw;
  397. }
  398.  
  399.  
  400. /*
  401. =================
  402. PF_vectoangles
  403.  
  404. vector vectoangles(vector)
  405. =================
  406. */
  407. void PF_vectoangles (void)
  408. {
  409.     float    *value1;
  410.     float    forward;
  411.     float    yaw, pitch;
  412.     
  413.     value1 = G_VECTOR(OFS_PARM0);
  414.  
  415.     if (value1[1] == 0 && value1[0] == 0)
  416.     {
  417.         yaw = 0;
  418.         if (value1[2] > 0)
  419.             pitch = 90;
  420.         else
  421.             pitch = 270;
  422.     }
  423.     else
  424.     {
  425.         yaw = (int) (atan2(value1[1], value1[0]) * 180 / M_PI);
  426.         if (yaw < 0)
  427.             yaw += 360;
  428.  
  429.         forward = sqrt (value1[0]*value1[0] + value1[1]*value1[1]);
  430.         pitch = (int) (atan2(value1[2], forward) * 180 / M_PI);
  431.         if (pitch < 0)
  432.             pitch += 360;
  433.     }
  434.  
  435.     G_FLOAT(OFS_RETURN+0) = pitch;
  436.     G_FLOAT(OFS_RETURN+1) = yaw;
  437.     G_FLOAT(OFS_RETURN+2) = 0;
  438. }
  439.  
  440. /*
  441. =================
  442. PF_Random
  443.  
  444. Returns a number from 0<= num < 1
  445.  
  446. random()
  447. =================
  448. */
  449. void PF_random (void)
  450. {
  451.     float        num;
  452.         
  453.     num = (rand ()&0x7fff) / ((float)0x7fff);
  454.     
  455.     G_FLOAT(OFS_RETURN) = num;
  456. }
  457.  
  458. /*
  459. =================
  460. PF_particle
  461.  
  462. particle(origin, color, count)
  463. =================
  464. */
  465. void PF_particle (void)
  466. {
  467.     float        *org, *dir;
  468.     float        color;
  469.     float        count;
  470.             
  471.     org = G_VECTOR(OFS_PARM0);
  472.     dir = G_VECTOR(OFS_PARM1);
  473.     color = G_FLOAT(OFS_PARM2);
  474.     count = G_FLOAT(OFS_PARM3);
  475.     SV_StartParticle (org, dir, color, count);
  476. }
  477.  
  478.  
  479. /*
  480. =================
  481. PF_ambientsound
  482.  
  483. =================
  484. */
  485. void PF_ambientsound (void)
  486. {
  487.     char        **check;
  488.     char        *samp;
  489.     float        *pos;
  490.     float         vol, attenuation;
  491.     int            i, soundnum;
  492.  
  493.     pos = G_VECTOR (OFS_PARM0);            
  494.     samp = G_STRING(OFS_PARM1);
  495.     vol = G_FLOAT(OFS_PARM2);
  496.     attenuation = G_FLOAT(OFS_PARM3);
  497.     
  498. // check to see if samp was properly precached
  499.     for (soundnum=0, check = sv.sound_precache ; *check ; check++, soundnum++)
  500.         if (!strcmp(*check,samp))
  501.             break;
  502.             
  503.     if (!*check)
  504.     {
  505.         Con_Printf ("no precache: %s\n", samp);
  506.         return;
  507.     }
  508.  
  509. // add an svc_spawnambient command to the level signon packet
  510.  
  511.     MSG_WriteByte (&sv.signon,svc_spawnstaticsound);
  512.     for (i=0 ; i<3 ; i++)
  513.         MSG_WriteCoord(&sv.signon, pos[i]);
  514.  
  515.     MSG_WriteByte (&sv.signon, soundnum);
  516.  
  517.     MSG_WriteByte (&sv.signon, vol*255);
  518.     MSG_WriteByte (&sv.signon, attenuation*64);
  519.  
  520. }
  521.  
  522. /*
  523. =================
  524. PF_sound
  525.  
  526. Each entity can have eight independant sound sources, like voice,
  527. weapon, feet, etc.
  528.  
  529. Channel 0 is an auto-allocate channel, the others override anything
  530. allready running on that entity/channel pair.
  531.  
  532. An attenuation of 0 will play full volume everywhere in the level.
  533. Larger attenuations will drop off.
  534.  
  535. =================
  536. */
  537. void PF_sound (void)
  538. {
  539.     char        *sample;
  540.     int            channel;
  541.     edict_t        *entity;
  542.     int         volume;
  543.     float attenuation;
  544.         
  545.     entity = G_EDICT(OFS_PARM0);
  546.     channel = G_FLOAT(OFS_PARM1);
  547.     sample = G_STRING(OFS_PARM2);
  548.     volume = G_FLOAT(OFS_PARM3) * 255;
  549.     attenuation = G_FLOAT(OFS_PARM4);
  550.     
  551.     if (volume < 0 || volume > 255)
  552.         Sys_Error ("SV_StartSound: volume = %i", volume);
  553.  
  554.     if (attenuation < 0 || attenuation > 4)
  555.         Sys_Error ("SV_StartSound: attenuation = %f", attenuation);
  556.  
  557.     if (channel < 0 || channel > 7)
  558.         Sys_Error ("SV_StartSound: channel = %i", channel);
  559.  
  560.     SV_StartSound (entity, channel, sample, volume, attenuation);
  561. }
  562.  
  563. /*
  564. =================
  565. PF_break
  566.  
  567. break()
  568. =================
  569. */
  570. void PF_break (void)
  571. {
  572. Con_Printf ("break statement\n");
  573. *(int *)-4 = 0;    // dump to debugger
  574. //    PR_RunError ("break statement");
  575. }
  576.  
  577. /*
  578. =================
  579. PF_traceline
  580.  
  581. Used for use tracing and shot targeting
  582. Traces are blocked by bbox and exact bsp entityes, and also slide box entities
  583. if the tryents flag is set.
  584.  
  585. traceline (vector1, vector2, tryents)
  586. =================
  587. */
  588. void PF_traceline (void)
  589. {
  590.     float    *v1, *v2;
  591.     trace_t    trace;
  592.     int        nomonsters;
  593.     edict_t    *ent;
  594.  
  595.     v1 = G_VECTOR(OFS_PARM0);
  596.     v2 = G_VECTOR(OFS_PARM1);
  597.     nomonsters = G_FLOAT(OFS_PARM2);
  598.     ent = G_EDICT(OFS_PARM3);
  599.  
  600.     trace = SV_Move (v1, vec3_origin, vec3_origin, v2, nomonsters, ent);
  601.  
  602.     pr_global_struct->trace_allsolid = trace.allsolid;
  603.     pr_global_struct->trace_startsolid = trace.startsolid;
  604.     pr_global_struct->trace_fraction = trace.fraction;
  605.     pr_global_struct->trace_inwater = trace.inwater;
  606.     pr_global_struct->trace_inopen = trace.inopen;
  607.     VectorCopy (trace.endpos, pr_global_struct->trace_endpos);
  608.     VectorCopy (trace.plane.normal, pr_global_struct->trace_plane_normal);
  609.     pr_global_struct->trace_plane_dist =  trace.plane.dist;    
  610.     if (trace.ent)
  611.         pr_global_struct->trace_ent = EDICT_TO_PROG(trace.ent);
  612.     else
  613.         pr_global_struct->trace_ent = EDICT_TO_PROG(sv.edicts);
  614. }
  615.  
  616. /*
  617. =================
  618. PF_checkpos
  619.  
  620. Returns true if the given entity can move to the given position from it's
  621. current position by walking or rolling.
  622. FIXME: make work...
  623. scalar checkpos (entity, vector)
  624. =================
  625. */
  626. void PF_checkpos (void)
  627. {
  628. }
  629.  
  630. //============================================================================
  631.  
  632. byte    checkpvs[MAX_MAP_LEAFS/8];
  633.  
  634. int PF_newcheckclient (int check)
  635. {
  636.     int        i;
  637.     byte    *pvs;
  638.     edict_t    *ent;
  639.     mleaf_t    *leaf;
  640.     vec3_t    org;
  641.  
  642. // cycle to the next one
  643.  
  644.     if (check < 1)
  645.         check = 1;
  646.     if (check > svs.maxclients)
  647.         check = svs.maxclients;
  648.  
  649.     if (check == svs.maxclients)
  650.         i = 1;
  651.     else
  652.         i = check + 1;
  653.  
  654.     for ( ;  ; i++)
  655.     {
  656.         if (i == svs.maxclients+1)
  657.             i = 1;
  658.  
  659.         ent = EDICT_NUM(i);
  660.  
  661.         if (i == check)
  662.             break;    // didn't find anything else
  663.  
  664.         if (ent->free)
  665.             continue;
  666.         if (ent->v.health <= 0)
  667.             continue;
  668.         if ((int)ent->v.flags & FL_NOTARGET)
  669.             continue;
  670.  
  671.     // anything that is a client, or has a client as an enemy
  672.         break;
  673.     }
  674.  
  675. // get the PVS for the entity
  676.     VectorAdd (ent->v.origin, ent->v.view_ofs, org);
  677.     leaf = Mod_PointInLeaf (org, sv.worldmodel);
  678.     pvs = Mod_LeafPVS (leaf, sv.worldmodel);
  679.     memcpy (checkpvs, pvs, (sv.worldmodel->numleafs+7)>>3 );
  680.  
  681.     return i;
  682. }
  683.  
  684. /*
  685. =================
  686. PF_checkclient
  687.  
  688. Returns a client (or object that has a client enemy) that would be a
  689. valid target.
  690.  
  691. If there are more than one valid options, they are cycled each frame
  692.  
  693. If (self.origin + self.viewofs) is not in the PVS of the current target,
  694. it is not returned at all.
  695.  
  696. name checkclient ()
  697. =================
  698. */
  699. #define    MAX_CHECK    16
  700. int c_invis, c_notvis;
  701. void PF_checkclient (void)
  702. {
  703.     edict_t    *ent, *self;
  704.     mleaf_t    *leaf;
  705.     int        l;
  706.     vec3_t    view;
  707.     
  708. // find a new check if on a new frame
  709.     if (sv.time - sv.lastchecktime >= 0.1)
  710.     {
  711.         sv.lastcheck = PF_newcheckclient (sv.lastcheck);
  712.         sv.lastchecktime = sv.time;
  713.     }
  714.  
  715. // return check if it might be visible    
  716.     ent = EDICT_NUM(sv.lastcheck);
  717.     if (ent->free || ent->v.health <= 0)
  718.     {
  719.         RETURN_EDICT(sv.edicts);
  720.         return;
  721.     }
  722.  
  723. // if current entity can't possibly see the check entity, return 0
  724.     self = PROG_TO_EDICT(pr_global_struct->self);
  725.     VectorAdd (self->v.origin, self->v.view_ofs, view);
  726.     leaf = Mod_PointInLeaf (view, sv.worldmodel);
  727.     l = (leaf - sv.worldmodel->leafs) - 1;
  728.     if ( (l<0) || !(checkpvs[l>>3] & (1<<(l&7)) ) )
  729.     {
  730. c_notvis++;
  731.         RETURN_EDICT(sv.edicts);
  732.         return;
  733.     }
  734.  
  735. // might be able to see it
  736. c_invis++;
  737.     RETURN_EDICT(ent);
  738. }
  739.  
  740. //============================================================================
  741.  
  742.  
  743. /*
  744. =================
  745. PF_stuffcmd
  746.  
  747. Sends text over to the client's execution buffer
  748.  
  749. stuffcmd (clientent, value)
  750. =================
  751. */
  752. void PF_stuffcmd (void)
  753. {
  754.     int        entnum;
  755.     char    *str;
  756.     client_t    *old;
  757.     
  758.     entnum = G_EDICTNUM(OFS_PARM0);
  759.     if (entnum < 1 || entnum > svs.maxclients)
  760.         PR_RunError ("Parm 0 not a client");
  761.     str = G_STRING(OFS_PARM1);    
  762.     
  763.     old = host_client;
  764.     host_client = &svs.clients[entnum-1];
  765.     Host_ClientCommands ("%s", str);
  766.     host_client = old;
  767. }
  768.  
  769. /*
  770. =================
  771. PF_localcmd
  772.  
  773. Sends text over to the client's execution buffer
  774.  
  775. localcmd (string)
  776. =================
  777. */
  778. void PF_localcmd (void)
  779. {
  780.     char    *str;
  781.     
  782.     str = G_STRING(OFS_PARM0);    
  783.     Cbuf_AddText (str);
  784. }
  785.  
  786. /*
  787. =================
  788. PF_cvar
  789.  
  790. float cvar (string)
  791. =================
  792. */
  793. void PF_cvar (void)
  794. {
  795.     char    *str;
  796.     
  797.     str = G_STRING(OFS_PARM0);
  798.     
  799.     G_FLOAT(OFS_RETURN) = Cvar_VariableValue (str);
  800. }
  801.  
  802. /*
  803. =================
  804. PF_cvar_set
  805.  
  806. float cvar (string)
  807. =================
  808. */
  809. void PF_cvar_set (void)
  810. {
  811.     char    *var, *val;
  812.     
  813.     var = G_STRING(OFS_PARM0);
  814.     val = G_STRING(OFS_PARM1);
  815.     
  816.     Cvar_Set (var, val);
  817. }
  818.  
  819. /*
  820. =================
  821. PF_findradius
  822.  
  823. Returns a chain of entities that have origins within a spherical area
  824.  
  825. findradius (origin, radius)
  826. =================
  827. */
  828. void PF_findradius (void)
  829. {
  830.     edict_t    *ent, *chain;
  831.     float    rad;
  832.     float    *org;
  833.     vec3_t    eorg;
  834.     int        i, j;
  835.  
  836.     chain = (edict_t *)sv.edicts;
  837.     
  838.     org = G_VECTOR(OFS_PARM0);
  839.     rad = G_FLOAT(OFS_PARM1);
  840.  
  841.     ent = NEXT_EDICT(sv.edicts);
  842.     for (i=1 ; i<sv.num_edicts ; i++, ent = NEXT_EDICT(ent))
  843.     {
  844.         if (ent->free)
  845.             continue;
  846.         if (ent->v.solid == SOLID_NOT)
  847.             continue;
  848.         for (j=0 ; j<3 ; j++)
  849.             eorg[j] = org[j] - (ent->v.origin[j] + (ent->v.mins[j] + ent->v.maxs[j])*0.5);            
  850.         if (Length(eorg) > rad)
  851.             continue;
  852.             
  853.         ent->v.chain = EDICT_TO_PROG(chain);
  854.         chain = ent;
  855.     }
  856.  
  857.     RETURN_EDICT(chain);
  858. }
  859.  
  860.  
  861. /*
  862. =========
  863. PF_dprint
  864. =========
  865. */
  866. void PF_dprint (void)
  867. {
  868.     Con_Printf ("%s",PF_VarString(0));
  869. }
  870.  
  871. char    pr_string_temp[128];
  872.  
  873. void PF_ftos (void)
  874. {
  875.     float    v;
  876.     v = G_FLOAT(OFS_PARM0);
  877.     
  878.     if (v == (int)v)
  879.         sprintf (pr_string_temp, "%d",(int)v);
  880.     else
  881.         sprintf (pr_string_temp, "%5.1f",v);
  882.     G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
  883. }
  884.  
  885. void PF_fabs (void)
  886. {
  887.     float    v;
  888.     v = G_FLOAT(OFS_PARM0);
  889.     G_FLOAT(OFS_RETURN) = fabs(v);
  890. }
  891.  
  892. void PF_vtos (void)
  893. {
  894.     sprintf (pr_string_temp, "'%5.1f %5.1f %5.1f'", G_VECTOR(OFS_PARM0)[0], G_VECTOR(OFS_PARM0)[1], G_VECTOR(OFS_PARM0)[2]);
  895.     G_INT(OFS_RETURN) = pr_string_temp - pr_strings;
  896. }
  897.  
  898. void PF_Spawn (void)
  899. {
  900.     edict_t    *ed;
  901.     ed = ED_Alloc();
  902.     RETURN_EDICT(ed);
  903. }
  904.  
  905. void PF_Remove (void)
  906. {
  907.     edict_t    *ed;
  908.     
  909.     ed = G_EDICT(OFS_PARM0);
  910.     ED_Free (ed);
  911. }
  912.  
  913.  
  914. // entity (entity start, .string field, string match) find = #5;
  915. void PF_Find (void)
  916. {
  917.     int        e;    
  918.     int        f;
  919.     char    *s, *t;
  920.     edict_t    *ed;
  921.     
  922.     e = G_EDICTNUM(OFS_PARM0);
  923.     f = G_INT(OFS_PARM1);
  924.     s = G_STRING(OFS_PARM2);
  925.     if (!s)
  926.         PR_RunError ("PF_Find: bad search string");
  927.         
  928.     for (e++ ; e < sv.num_edicts ; e++)
  929.     {
  930.         ed = EDICT_NUM(e);
  931.         if (ed->free)
  932.             continue;
  933.         t = E_STRING(ed,f);
  934.         if (!t)
  935.             continue;
  936.         if (!strcmp(t,s))
  937.         {
  938.             RETURN_EDICT(ed);
  939.             return;
  940.         }
  941.     }
  942.     
  943.     RETURN_EDICT(sv.edicts);
  944. }
  945.  
  946. void PR_CheckEmptyString (char *s)
  947. {
  948.     if (s[0] <= ' ')
  949.         PR_RunError ("Bad string");
  950. }
  951.  
  952. void PF_precache_file (void)
  953. {    // precache_file is only used to copy files with qcc, it does nothing
  954.     G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
  955. }
  956.  
  957. void PF_precache_sound (void)
  958. {
  959.     char    *s;
  960.     int        i;
  961.     
  962.     if (sv.state != ss_loading)
  963.         PR_RunError ("PF_Precache_*: Precache can only be done in spawn functions");
  964.         
  965.     s = G_STRING(OFS_PARM0);
  966.     G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
  967.     PR_CheckEmptyString (s);
  968.     
  969.     for (i=0 ; i<MAX_SOUNDS ; i++)
  970.     {
  971.         if (!sv.sound_precache[i])
  972.         {
  973.             sv.sound_precache[i] = s;
  974.             return;
  975.         }
  976.         if (!strcmp(sv.sound_precache[i], s))
  977.             return;
  978.     }
  979.     PR_RunError ("PF_precache_sound: overflow");
  980. }
  981.  
  982. void PF_precache_model (void)
  983. {
  984.     char    *s;
  985.     int        i;
  986.     
  987.     if (sv.state != ss_loading)
  988.         PR_RunError ("PF_Precache_*: Precache can only be done in spawn functions");
  989.         
  990.     s = G_STRING(OFS_PARM0);
  991.     G_INT(OFS_RETURN) = G_INT(OFS_PARM0);
  992.     PR_CheckEmptyString (s);
  993.  
  994.     for (i=0 ; i<MAX_MODELS ; i++)
  995.     {
  996.         if (!sv.model_precache[i])
  997.         {
  998.             sv.model_precache[i] = s;
  999.             sv.models[i] = Mod_ForName (s, true);
  1000.             return;
  1001.         }
  1002.         if (!strcmp(sv.model_precache[i], s))
  1003.             return;
  1004.     }
  1005.     PR_RunError ("PF_precache_model: overflow");
  1006. }
  1007.  
  1008.  
  1009. void PF_coredump (void)
  1010. {
  1011.     ED_PrintEdicts ();
  1012. }
  1013.  
  1014. void PF_traceon (void)
  1015. {
  1016.     pr_trace = true;
  1017. }
  1018.  
  1019. void PF_traceoff (void)
  1020. {
  1021.     pr_trace = false;
  1022. }
  1023.  
  1024. void PF_eprint (void)
  1025. {
  1026.     ED_PrintNum (G_EDICTNUM(OFS_PARM0));
  1027. }
  1028.  
  1029. /*
  1030. ===============
  1031. PF_walkmove
  1032.  
  1033. float(float yaw, float dist) walkmove
  1034. ===============
  1035. */
  1036. void PF_walkmove (void)
  1037. {
  1038.     edict_t    *ent;
  1039.     float    yaw, dist;
  1040.     vec3_t    move;
  1041.     dfunction_t    *oldf;
  1042.     int     oldself;
  1043.     
  1044.     ent = PROG_TO_EDICT(pr_global_struct->self);
  1045.     yaw = G_FLOAT(OFS_PARM0);
  1046.     dist = G_FLOAT(OFS_PARM1);
  1047.     
  1048.     if ( !( (int)ent->v.flags & (FL_ONGROUND|FL_FLY|FL_SWIM) ) )
  1049.     {
  1050.         G_FLOAT(OFS_RETURN) = 0;
  1051.         return;
  1052.     }
  1053.  
  1054.     yaw = yaw*M_PI*2 / 360;
  1055.     
  1056.     move[0] = cos(yaw)*dist;
  1057.     move[1] = sin(yaw)*dist;
  1058.     move[2] = 0;
  1059.  
  1060. // save program state, because SV_movestep may call other progs
  1061.     oldf = pr_xfunction;
  1062.     oldself = pr_global_struct->self;
  1063.     
  1064.     G_FLOAT(OFS_RETURN) = SV_movestep(ent, move, true);
  1065.     
  1066.     
  1067. // restore program state
  1068.     pr_xfunction = oldf;
  1069.     pr_global_struct->self = oldself;
  1070. }
  1071. /*
  1072. ===============
  1073. PF_droptofloor
  1074.  
  1075. void() droptofloor
  1076. ===============
  1077. */
  1078. void PF_droptofloor (void)
  1079. {
  1080.     edict_t        *ent;
  1081.     vec3_t        end;
  1082.     trace_t        trace;
  1083.     
  1084.     ent = PROG_TO_EDICT(pr_global_struct->self);
  1085.  
  1086.     VectorCopy (ent->v.origin, end);
  1087.     end[2] -= 256;
  1088.     
  1089.     trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, end, false, ent);
  1090.  
  1091.     if (trace.fraction == 1 || trace.allsolid)
  1092.         G_FLOAT(OFS_RETURN) = 0;
  1093.     else
  1094.     {
  1095.         VectorCopy (trace.endpos, ent->v.origin);
  1096.         SV_LinkEdict (ent, false);
  1097.         ent->v.flags = (int)ent->v.flags | FL_ONGROUND;
  1098.         ent->v.groundentity = EDICT_TO_PROG(trace.ent);
  1099.         G_FLOAT(OFS_RETURN) = 1;
  1100.     }
  1101. }
  1102.  
  1103. /*
  1104. ===============
  1105. PF_lightstyle
  1106.  
  1107. void(float style, string value) lightstyle
  1108. ===============
  1109. */
  1110. void PF_lightstyle (void)
  1111. {
  1112.     int        style;
  1113.     char    *val;
  1114.     client_t    *client;
  1115.     int            j;
  1116.     
  1117.     style = G_FLOAT(OFS_PARM0);
  1118.     val = G_STRING(OFS_PARM1);
  1119.  
  1120. // change the string in sv
  1121.     sv.lightstyles[style] = val;
  1122.     
  1123. // send message to all clients on this server
  1124.     if (sv.state != ss_active)
  1125.         return;
  1126.     
  1127.     for (j=0, client = svs.clients ; j<svs.maxclients ; j++, client++)
  1128.         if (client->active || client->spawned)
  1129.         {
  1130.             MSG_WriteChar (&client->message, svc_lightstyle);
  1131.             MSG_WriteChar (&client->message,style);
  1132.             MSG_WriteString (&client->message, val);
  1133.         }
  1134. }
  1135.  
  1136. void PF_rint (void)
  1137. {
  1138.     float    f;
  1139.     f = G_FLOAT(OFS_PARM0);
  1140.     if (f > 0)
  1141.         G_FLOAT(OFS_RETURN) = (int)(f + 0.5);
  1142.     else
  1143.         G_FLOAT(OFS_RETURN) = (int)(f - 0.5);
  1144. }
  1145. void PF_floor (void)
  1146. {
  1147.     G_FLOAT(OFS_RETURN) = floor(G_FLOAT(OFS_PARM0));
  1148. }
  1149. void PF_ceil (void)
  1150. {
  1151.     G_FLOAT(OFS_RETURN) = ceil(G_FLOAT(OFS_PARM0));
  1152. }
  1153.  
  1154. /*
  1155. =============
  1156. PF_checkbottom
  1157. =============
  1158. */
  1159. void PF_checkbottom (void)
  1160. {
  1161.     edict_t    *ent;
  1162.     
  1163.     ent = G_EDICT(OFS_PARM0);
  1164.  
  1165.     G_FLOAT(OFS_RETURN) = SV_CheckBottom (ent);
  1166. }
  1167.  
  1168. /*
  1169. =============
  1170. PF_pointcontents
  1171. =============
  1172. */
  1173. void PF_pointcontents (void)
  1174. {
  1175.     float    *v;
  1176.     
  1177.     v = G_VECTOR(OFS_PARM0);
  1178.  
  1179.     G_FLOAT(OFS_RETURN) = SV_PointContents (v);    
  1180. }
  1181.  
  1182. /*
  1183. =============
  1184. PF_nextent
  1185.  
  1186. entity nextent(entity)
  1187. =============
  1188. */
  1189. void PF_nextent (void)
  1190. {
  1191.     int        i;
  1192.     edict_t    *ent;
  1193.     
  1194.     i = G_EDICTNUM(OFS_PARM0);
  1195.     while (1)
  1196.     {
  1197.         i++;
  1198.         if (i == sv.num_edicts)
  1199.         {
  1200.             RETURN_EDICT(sv.edicts);
  1201.             return;
  1202.         }
  1203.         ent = EDICT_NUM(i);
  1204.         if (!ent->free)
  1205.         {
  1206.             RETURN_EDICT(ent);
  1207.             return;
  1208.         }
  1209.     }
  1210. }
  1211.  
  1212. /*
  1213. =============
  1214. PF_aim
  1215.  
  1216. Pick a vector for the player to shoot along
  1217. vector aim(entity, missilespeed)
  1218. =============
  1219. */
  1220. cvar_t    sv_aim = {"sv_aim", "0.93"};
  1221. void PF_aim (void)
  1222. {
  1223.     edict_t    *ent, *check, *bestent;
  1224.     vec3_t    start, dir, end, bestdir;
  1225.     int        i, j;
  1226.     trace_t    tr;
  1227.     float    dist, bestdist;
  1228.     float    speed;
  1229.     
  1230.     ent = G_EDICT(OFS_PARM0);
  1231.     speed = G_FLOAT(OFS_PARM1);
  1232.  
  1233.     VectorCopy (ent->v.origin, start);
  1234.     start[2] += 20;
  1235.  
  1236. // try sending a trace straight
  1237.     VectorCopy (pr_global_struct->v_forward, dir);
  1238.     VectorMA (start, 2048, dir, end);
  1239.     tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent);
  1240.     if (tr.ent && tr.ent->v.takedamage == DAMAGE_AIM
  1241.     && (!teamplay.value || ent->v.team <=0 || ent->v.team != tr.ent->v.team) )
  1242.     {
  1243.         VectorCopy (pr_global_struct->v_forward, G_VECTOR(OFS_RETURN));
  1244.         return;
  1245.     }
  1246.  
  1247.  
  1248. // try all possible entities
  1249.     VectorCopy (dir, bestdir);
  1250.     bestdist = sv_aim.value;
  1251.     bestent = NULL;
  1252.     
  1253.     check = NEXT_EDICT(sv.edicts);
  1254.     for (i=1 ; i<sv.num_edicts ; i++, check = NEXT_EDICT(check) )
  1255.     {
  1256.         if (check->v.takedamage != DAMAGE_AIM)
  1257.             continue;
  1258.         if (check == ent)
  1259.             continue;
  1260.         if (teamplay.value && ent->v.team > 0 && ent->v.team == check->v.team)
  1261.             continue;    // don't aim at teammate
  1262.         for (j=0 ; j<3 ; j++)
  1263.             end[j] = check->v.origin[j]
  1264.             + 0.5*(check->v.mins[j] + check->v.maxs[j]);
  1265.         VectorSubtract (end, start, dir);
  1266.         VectorNormalize (dir);
  1267.         dist = DotProduct (dir, pr_global_struct->v_forward);
  1268.         if (dist < bestdist)
  1269.             continue;    // to far to turn
  1270.         tr = SV_Move (start, vec3_origin, vec3_origin, end, false, ent);
  1271.         if (tr.ent == check)
  1272.         {    // can shoot at this one
  1273.             bestdist = dist;
  1274.             bestent = check;
  1275.         }
  1276.     }
  1277.     
  1278.     if (bestent)
  1279.     {
  1280.         VectorSubtract (bestent->v.origin, ent->v.origin, dir);
  1281.         dist = DotProduct (dir, pr_global_struct->v_forward);
  1282.         VectorScale (pr_global_struct->v_forward, dist, end);
  1283.         end[2] = dir[2];
  1284.         VectorNormalize (end);
  1285.         VectorCopy (end, G_VECTOR(OFS_RETURN));    
  1286.     }
  1287.     else
  1288.     {
  1289.         VectorCopy (bestdir, G_VECTOR(OFS_RETURN));
  1290.     }
  1291. }
  1292.  
  1293. /*
  1294. ==============
  1295. PF_changeyaw
  1296.  
  1297. This was a major timewaster in progs, so it was converted to C
  1298. ==============
  1299. */
  1300. void PF_changeyaw (void)
  1301. {
  1302.     edict_t        *ent;
  1303.     float        ideal, current, move, speed;
  1304.     
  1305.     ent = PROG_TO_EDICT(pr_global_struct->self);
  1306.     current = anglemod( ent->v.angles[1] );
  1307.     ideal = ent->v.ideal_yaw;
  1308.     speed = ent->v.yaw_speed;
  1309.     
  1310.     if (current == ideal)
  1311.         return;
  1312.     move = ideal - current;
  1313.     if (ideal > current)
  1314.     {
  1315.         if (move >= 180)
  1316.             move = move - 360;
  1317.     }
  1318.     else
  1319.     {
  1320.         if (move <= -180)
  1321.             move = move + 360;
  1322.     }
  1323.     if (move > 0)
  1324.     {
  1325.         if (move > speed)
  1326.             move = speed;
  1327.     }
  1328.     else
  1329.     {
  1330.         if (move < -speed)
  1331.             move = -speed;
  1332.     }
  1333.     
  1334.     ent->v.angles[1] = anglemod (current + move);
  1335. }
  1336.  
  1337. /*
  1338. ===============================================================================
  1339.  
  1340. MESSAGE WRITING
  1341.  
  1342. ===============================================================================
  1343. */
  1344.  
  1345. #define    MSG_BROADCAST    0        // unreliable to all
  1346. #define    MSG_ONE            1        // reliable to one (msg_entity)
  1347. #define    MSG_ALL            2        // reliable to all
  1348. #define    MSG_INIT        3        // write to the init string
  1349.  
  1350. sizebuf_t *WriteDest (void)
  1351. {
  1352.     int        entnum;
  1353.     int        dest;
  1354.     edict_t    *ent;
  1355.  
  1356.     dest = G_FLOAT(OFS_PARM0);
  1357.     switch (dest)
  1358.     {
  1359.     case MSG_BROADCAST:
  1360.         return &sv.datagram;
  1361.     
  1362.     case MSG_ONE:
  1363.         ent = PROG_TO_EDICT(pr_global_struct->msg_entity);
  1364.         entnum = NUM_FOR_EDICT(ent);
  1365.         if (entnum < 1 || entnum > svs.maxclients)
  1366.             PR_RunError ("WriteDest: not a client");
  1367.         return &svs.clients[entnum-1].message;
  1368.         
  1369.     case MSG_ALL:
  1370.         return &sv.reliable_datagram;
  1371.     
  1372.     case MSG_INIT:
  1373.         return &sv.signon;
  1374.  
  1375.     default:
  1376.         PR_RunError ("WriteDest: bad destination");
  1377.         break;
  1378.     }
  1379.     
  1380.     return NULL;
  1381. }
  1382.  
  1383. void PF_WriteByte (void)
  1384. {
  1385.     MSG_WriteByte (WriteDest(), G_FLOAT(OFS_PARM1));
  1386. }
  1387.  
  1388. void PF_WriteChar (void)
  1389. {
  1390.     MSG_WriteChar (WriteDest(), G_FLOAT(OFS_PARM1));
  1391. }
  1392.  
  1393. void PF_WriteShort (void)
  1394. {
  1395.     MSG_WriteShort (WriteDest(), G_FLOAT(OFS_PARM1));
  1396. }
  1397.  
  1398. void PF_WriteLong (void)
  1399. {
  1400.     MSG_WriteLong (WriteDest(), G_FLOAT(OFS_PARM1));
  1401. }
  1402.  
  1403. void PF_WriteAngle (void)
  1404. {
  1405.     MSG_WriteAngle (WriteDest(), G_FLOAT(OFS_PARM1));
  1406. }
  1407.  
  1408. void PF_WriteCoord (void)
  1409. {
  1410.     MSG_WriteCoord (WriteDest(), G_FLOAT(OFS_PARM1));
  1411. }
  1412.  
  1413. void PF_WriteString (void)
  1414. {
  1415.     MSG_WriteString (WriteDest(), G_STRING(OFS_PARM1));
  1416. }
  1417.  
  1418.  
  1419. void PF_WriteEntity (void)
  1420. {
  1421.     MSG_WriteShort (WriteDest(), G_EDICTNUM(OFS_PARM1));
  1422. }
  1423.  
  1424. //=============================================================================
  1425.  
  1426. int SV_ModelIndex (char *name);
  1427.  
  1428. void PF_makestatic (void)
  1429. {
  1430.     edict_t    *ent;
  1431.     int        i;
  1432.     
  1433.     ent = G_EDICT(OFS_PARM0);
  1434.  
  1435.     MSG_WriteByte (&sv.signon,svc_spawnstatic);
  1436.  
  1437.     MSG_WriteByte (&sv.signon, SV_ModelIndex(pr_strings + ent->v.model));
  1438.  
  1439.     MSG_WriteByte (&sv.signon, ent->v.frame);
  1440.     MSG_WriteByte (&sv.signon, ent->v.colormap);
  1441.     MSG_WriteByte (&sv.signon, ent->v.skin);
  1442.     for (i=0 ; i<3 ; i++)
  1443.     {
  1444.         MSG_WriteCoord(&sv.signon, ent->v.origin[i]);
  1445.         MSG_WriteAngle(&sv.signon, ent->v.angles[i]);
  1446.     }
  1447.  
  1448. // throw the entity away now
  1449.     ED_Free (ent);
  1450. }
  1451.  
  1452. //=============================================================================
  1453.  
  1454. /*
  1455. ==============
  1456. PF_setspawnparms
  1457. ==============
  1458. */
  1459. void PF_setspawnparms (void)
  1460. {
  1461.     edict_t    *ent;
  1462.     int        i;
  1463.     client_t    *client;
  1464.  
  1465.     ent = G_EDICT(OFS_PARM0);
  1466.     i = NUM_FOR_EDICT(ent);
  1467.     if (i < 1 || i > svs.maxclients)
  1468.         PR_RunError ("Entity is not a client");
  1469.  
  1470.     // copy spawn parms out of the client_t
  1471.     client = svs.clients + (i-1);
  1472.  
  1473.     for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
  1474.         (&pr_global_struct->parm1)[i] = client->spawn_parms[i];
  1475. }
  1476.  
  1477.  
  1478.  
  1479. /*
  1480. ==============
  1481. PF_changelevel
  1482. ==============
  1483. */
  1484. void PF_changelevel (void)
  1485. {
  1486.     char    *s;
  1487.  
  1488. // make sure we don't issue two changelevels
  1489.     if (svs.changelevel_issued)
  1490.         return;
  1491.     svs.changelevel_issued = true;
  1492.     
  1493.     s = G_STRING(OFS_PARM0);
  1494.     Cbuf_AddText (va("changelevel %s\n",s));
  1495. }
  1496.  
  1497.  
  1498. void PF_Fixme (void)
  1499. {
  1500.     PR_RunError ("unimplemented bulitin");
  1501. }
  1502.  
  1503.  
  1504.  
  1505. builtin_t pr_builtin[] =
  1506. {
  1507.     PF_Fixme,
  1508. PF_makevectors,    // void(entity e)    makevectors         = #1;
  1509. PF_setorigin,    // void(entity e, vector o) setorigin    = #2;
  1510. PF_setmodel,    // void(entity e, string m) setmodel    = #3;
  1511. PF_setsize,    // void(entity e, vector min, vector max) setsize = #4;
  1512. PF_Fixme,
  1513. PF_break,    // void() break                        = #6;
  1514. PF_random,    // float() random                        = #7;
  1515. PF_sound,    // void(entity e, float chan, string samp) sound = #8;
  1516. PF_normalize,    // vector(vector v) normalize            = #9;
  1517. PF_error,       // void(string e) error                         = #10;
  1518. PF_objerror,    // void(string e) objerror                              = #11;
  1519. PF_vlen,    // float(vector v) vlen                = #12;
  1520. PF_vectoyaw,    // float(vector v) vectoyaw        = #13;
  1521. PF_Spawn,    // entity() spawn                        = #14;
  1522. PF_Remove,    // void(entity e) remove                = #15;
  1523. PF_traceline,    // float(vector v1, vector v2, float tryents) traceline = #16;
  1524. PF_checkclient,    // entity() clientlist                    = #17;
  1525. PF_Find,    // entity(entity start, .string fld, string match) find = #18;
  1526. PF_precache_sound,    // void(string s) precache_sound        = #19;
  1527. PF_precache_model,    // void(string s) precache_model        = #20;
  1528. PF_stuffcmd,    // void(entity client, string s)stuffcmd = #21;
  1529. PF_findradius,    // entity(vector org, float rad) findradius = #22;
  1530. PF_bprint,    // void(string s) bprint                = #23;
  1531. PF_sprint,    // void(entity client, string s) sprint = #24;
  1532. PF_dprint,      // void(string s) dprint                                = #25;
  1533. PF_ftos,    // void(string s) ftos                = #26;
  1534. PF_vtos,    // void(string s) vtos                = #27;
  1535. PF_coredump,
  1536. PF_traceon,
  1537. PF_traceoff,
  1538. PF_eprint,    // void(entity e) debug print an entire entity
  1539. PF_walkmove, // float(float yaw, float dist) walkmove
  1540. PF_Fixme, // float(float yaw, float dist) walkmove
  1541. PF_droptofloor,
  1542. PF_lightstyle,
  1543. PF_rint,
  1544. PF_floor,
  1545. PF_ceil,
  1546. PF_Fixme,
  1547. PF_checkbottom,
  1548. PF_pointcontents,
  1549. PF_Fixme,
  1550. PF_fabs,
  1551. PF_aim,
  1552. PF_cvar,
  1553. PF_localcmd,
  1554. PF_nextent,
  1555. PF_particle,
  1556. PF_changeyaw,
  1557. PF_Fixme,
  1558. PF_vectoangles,
  1559.  
  1560. PF_WriteByte,
  1561. PF_WriteChar,
  1562. PF_WriteShort,
  1563. PF_WriteLong,
  1564. PF_WriteCoord,
  1565. PF_WriteAngle,
  1566. PF_WriteString,
  1567. PF_WriteEntity,
  1568.  
  1569. PF_Fixme,
  1570. PF_Fixme,
  1571. PF_Fixme,
  1572. PF_Fixme,
  1573. PF_Fixme,
  1574. PF_Fixme,
  1575. PF_Fixme,
  1576.  
  1577. SV_MoveToGoal,
  1578. PF_precache_file,
  1579. PF_makestatic,
  1580.  
  1581. PF_changelevel,
  1582. PF_Fixme,
  1583.  
  1584. PF_cvar_set,
  1585. PF_centerprint,
  1586.  
  1587. PF_ambientsound,
  1588.  
  1589. PF_precache_model,
  1590. PF_precache_sound,        // precache_sound2 is different only for qcc
  1591. PF_precache_file,
  1592.  
  1593. PF_setspawnparms,
  1594. };
  1595.  
  1596. builtin_t *pr_builtins = pr_builtin;
  1597. int pr_numbuiltins = sizeof(pr_builtin)/sizeof(pr_builtin[0]);
  1598.  
  1599.